package main.common;

import java.io.*;
import java.net.Socket;

public class LogicThread extends Thread implements Serializable {
    static Socket socket;
    InputStream inputStream;
    OutputStream outputStream;

    public LogicThread(Socket socket){
        this.socket = socket;
        start();
    }
    public void run(){
        try {
            new Thread(() -> {
                BufferedReader bufferedReader = null;
                try {
                    bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                    String temp;
                    while ((temp = bufferedReader.readLine()) != null){
//                        if (temp.equals("heart......")){
//                            continue;
//                        }
                        System.out.println(temp);
                    }
//                    synchronized (ThreadLock.lockobj){
//                        ThreadLock.lockobj.notify();
//                        ThreadLock.lockobj.wait();
//                    }
                } catch (Exception e) {
                    System.out.printf("bufferReader error: %s\n", e);
                    e.printStackTrace();
                }
            }).start();
        } catch (Exception e){
            System.out.printf("logic thread error: %s\n", e);
            e.printStackTrace();
        }finally {
            close();
        }
    }

    private void close() {
        try{
//            outputStream.close();
//            inputStream.close();
            socket.close();
        }catch (Exception e){
            System.out.printf("close socket error: %s\n", e);
            e.printStackTrace();
        }
    }
}